package offer;

import org.junit.Test;

import java.util.*;

public class offer31 {

    @Test
    public void test(){
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.toArray(new Integer[list.size()]);
        Collections.reverse(list);
        int a = 7;
        System.out.println((a & 1) == 0);
    }

    public static void main(String[] args) {
        final Solution solution = new Solution();
        int[] pushed = {1,2,3,4,5};
        int[] poped = {4,5,3,2,1};
        System.out.println(solution.validateStackSequences(pushed,poped));
    }

    static class Solution {
        public boolean validateStackSequences(int[] pushed, int[] popped) {
            Deque<Integer> stack = new LinkedList<>();
            int i = 0;
            for(int j = 0; j < pushed.length; j++){
                stack.push(pushed[j]);
                while(stack .size() != 0 && stack.peek() == popped[i]){
                    stack.pop();
                    i++;
                }
            }
            return stack.isEmpty();
        }
    }
}
